#include "stdafx.h"
#include "resource.h"
#include "NewMarkerDialog.h"
#include "afxdialogex.h"

IMPLEMENT_DYNAMIC(NewMarkerDialog, CDialogEx)
NewMarkerDialog::NewMarkerDialog(double Value, CString Caption, COLORREF Color, CWnd* pParent /*=NULL*/)
    : CDialogEx(NewMarkerDialog::IDD, pParent),
      m_MarkerValue(Value),
      m_MarkerCaption(Caption),
      m_MarkerColor(Color)
{
    m_ShowType = false;
}

NewMarkerDialog::NewMarkerDialog(CWnd* pParent)
    : CDialogEx(NewMarkerDialog::IDD, pParent)
{
    m_ShowType = false;
}

NewMarkerDialog::~NewMarkerDialog()
{
}

void NewMarkerDialog::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_EDIT1, m_EditValue);
    DDX_Control(pDX, IDC_EDIT2, m_EditCaption);
    DDX_Control(pDX, IDC_MFCCOLORBUTTON1, m_ColorPicker);
    DDX_Control(pDX, IDC_COMBO_TYPE, m_Combo_Type);
}

BEGIN_MESSAGE_MAP(NewMarkerDialog, CDialogEx)
    ON_BN_CLICKED(IDOK, &NewMarkerDialog::OnBnClickedOk)
    ON_WM_SHOWWINDOW()
END_MESSAGE_MAP()

void NewMarkerDialog::OnBnClickedOk()
{
    CString Temp;
    m_EditValue.GetWindowText(Temp);
    swscanf_s(Temp, _T("%lf"), &m_MarkerValue);
    m_EditCaption.GetWindowText(m_MarkerCaption);
    m_MarkerColor = m_ColorPicker.GetColor();
    m_Combo_Type.GetLBText(m_Combo_Type.GetCurSel(), Temp);
    m_Type  = Temp[0];
    CDialogEx::OnOK();
}

void NewMarkerDialog::OnShowWindow(BOOL bShow, UINT nStatus)
{
    if(bShow)
    {
        m_ColorPicker.EnableOtherButton(_T("Other"), FALSE, TRUE);
        m_ColorPicker.SetColor(0);
        m_MarkerColor = 0;
        m_EditCaption.SetWindowText(m_MarkerCaption);
        CString Temp;
        Temp.Format(_T("%.5E"), m_MarkerValue);
        m_EditValue.SetWindowText(Temp);
        m_Combo_Type.SetCurSel(0);

        if(m_ShowType)
        {
            m_EditValue.SetWindowTextW(L"0");
            m_Combo_Type.ShowWindow(TRUE);
        }

        m_EditCaption.SetFocus();
    }

    CDialogEx::OnShowWindow(bShow, nStatus);
}
